package v1alpha1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type JVMHBaseChaosSpec struct {
	// ContainerSelector specifies the target for injection
	ContainerSelector `json:",inline"`

	// BladeCommonSpec contains basic spec of blade chaos action
	// +optional
	BladeCommonSpec `json:",inline"`

	// Duration represents the duration of the chaos
	// +optional
	Duration *string `json:"duration,omitempty"`

	// Action defines the specific jvm http action.
	Action JVMHBaseAction `json:"action"`

	// +optional
	// the latency duration for action 'latency', unit ms
	LatencyDuration int `json:"latency"`
	// +optional
	Offset int `json:"offset"`

	// +optional
	// the exception which needs to throw for action `exception`
	ThrowException string `json:"exception"`

	// +optional
	Table string `json:"table"`

	// RemoteCluster represents the remote cluster where the chaos will be deployed
	// +optional
	RemoteCluster string `json:"remoteCluster,omitempty"`
}

type JVMHBaseAction string

// latency、exception
const (
	JVMHBaseActionLatency   JVMHBaseAction = "latency"
	JVMHBaseActionException JVMHBaseAction = "exception"
)

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="action",type=string,JSONPath=`.spec.action`
// +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration`
// +chaos-mesh:experiment

type JVMHBaseChaos struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   JVMHBaseChaosSpec `json:"spec"`
	Status BladeChaosStatus  `json:"status,omitempty"`
}

var _ InnerObjectWithCustomStatus = (*JVMHBaseChaos)(nil)
var _ InnerObjectWithSelector = (*JVMHBaseChaos)(nil)
var _ InnerObject = (*JVMHBaseChaos)(nil)

func init() {
	SchemeBuilder.Register(&JVMHBaseChaos{}, &JVMHBaseChaosList{})
}

// GetSelectorSpecs is a getter for selectors
func (obj *JVMHBaseChaos) GetSelectorSpecs() map[string]interface{} {
	return map[string]interface{}{
		".": &obj.Spec.ContainerSelector,
	}
}

func (obj *JVMHBaseChaos) GetCustomStatus() interface{} {
	return &obj.Status.BladeChaosCustomStatus
}
